package cn.itcast.mq.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;


@Slf4j
@Component
public class JsTest {

    private int a = 1;
    private int b = 1;

    @RabbitListener(queues = "simple.queue")
    public void listner1(String msg) throws InterruptedException {
        System.out.println("a接收到"+msg+a);
        a++;
        Thread.sleep(20);
    }

    @RabbitListener(queues = "simple.queue")
    public void listner2(String msg) throws InterruptedException {
        System.out.println("b接收到"+msg+b);
        b++;
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void fnq1(String msg){
        System.out.println("消费者1接收到消息"+msg);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void fnq2(String msg){
        System.out.println("消费者2接收到消息"+msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue1"),
            exchange = @Exchange(name = "direct.exchange",type = ExchangeTypes.DIRECT),
            key = {"red","blue"}
    ))
    public void direct1(String msg){
        System.out.println("direct1收到消息"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue2"),
            exchange = @Exchange(name = "direct.exchange",type = ExchangeTypes.DIRECT),
            key = {"black","red"}
    ))
    public void direct2(String msg){
        System.out.println("direct2接收到消息"+msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue3"),
            exchange = @Exchange(name = "direct.exchange2"),
            key = "love"
    ))
    public void test03(Map map){
        System.out.println("03接收到消息内容"+map);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "topic.exchange",type = ExchangeTypes.TOPIC),
            key = "china.#"
    ))
    public void topic01(String msg){
        System.out.println("topic1接收到消息"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue2"),
            exchange = @Exchange(name = "topic.exchange",type = ExchangeTypes.TOPIC),
            key = "#.com"
    ))
    public void topic2(String msg){
        System.out.println("topic2接收到的消息"+msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue3"),
            exchange = @Exchange(name = "topic.exchange",type = ExchangeTypes.TOPIC),
            key = "#"
    ))
    public void topic3(String msg){
        System.out.println("万能接受王+"+msg);
    }

    @RabbitListener(queues = "objects.queue")
    public void object06(String map){
        System.out.println("objectQueue接受到了"+map);
    }
}


